﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.ObjectModel.Screens;
using Infrastructure.ObjectModel;
using B10_Ex02_Elad_034695114_Meyron_026607788.ObjectModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using B10_Ex02_EladLebovitch_034695114.ObjectModel;

namespace B10_Ex02_EladLebovitch_034695114.Screens
{
    public class GameOverScreen : GameScreen
    {
        private SpriteFont m_PauseFont;
        private SpriteFont m_ResumeFont;
        private Vector2 m_MessagePosition;
        
        public string MessageText 
        {
            get;
            set;
        }

        public GameOverScreen(Game i_Game)
            : base(i_Game)
        {
            this.IsModal = true;
            this.IsOverlayed = true;
            this.BlackTintAlpha = 60;
        }

        public GameOverScreen(Game i_Game, string i_MessageText) : this(i_Game)
        {
            this.MessageText = i_MessageText;
        }

        protected override void LoadContent()
        {
            base.LoadContent();
            m_PauseFont = ContentManager.Load<SpriteFont>(@"Fonts\ReadyFont");
            m_ResumeFont = ContentManager.Load<SpriteFont>(@"Fonts\InstuctionsFont");
        }

        public override void Initialize()
        {
            base.Initialize();

            // Set the positions for the text
            m_MessagePosition = new Vector2(90, CenterOfViewPort.Y - 100);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            SpriteBatch.Begin();
            SpriteBatch.DrawString(m_PauseFont, 
                                    "Game Over!", m_MessagePosition, Color.Red);
            SpriteBatch.DrawString(
                m_ResumeFont, 
                MessageText + "\n--------------------\n" +
                                                 "Press Esc to Exit\n" +
                                                 "Press R for a new game\n" +
                                                 "Press O for Main Menu", 
                                                 CenterOfViewPort, 
                                                 Color.White);
            SpriteBatch.End();
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Check what the user wants
            if (InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.R))
            {
                (Game.Services.GetService(typeof(GameFlow)) as GameFlow).RestartGameScreensForGame();                
                this.ExitScreen();
            }
            else if (InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                this.Game.Exit();
            }
            else if (InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.O))
            {
                (Game.Services.GetService(typeof(GameFlow)) as GameFlow).RestartGameScreensForMenu();
                this.ExitScreen();
            }
        }
    }
}